package cn.otrue.patienthealthmanager.adapter;

import java.util.Date;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cn.otrue.patienthealthmanager.R;
import cn.otrue.patienthealthmanager.utils.CommonUtil;
import cn.otrue.patienthealthmanager.utils.DensityUtil;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

public class Doctorpinglundpater extends BaseAdapter {
	public void ImageSet(String imgurl, ImageView img_headPhoto) {

		DisplayImageOptions options = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.iv_user_photo)
				.showImageOnFail(R.drawable.iv_user_photo)
				.cacheInMemory(true)
				.cacheOnDisk(true)
				.bitmapConfig(Bitmap.Config.RGB_565)
				.displayer(
						new RoundedBitmapDisplayer(DensityUtil.dip2px(context,
								40))).build();
		ImageLoader.getInstance().displayImage(imgurl, img_headPhoto, options);
	}
	private List<Map<String, String>> goods;
	private LayoutInflater inflater;
	private Context context;
	
	
	public Doctorpinglundpater(List<Map<String, String>> goods,
			Context context ) {
		this.goods = goods;
		inflater = LayoutInflater.from(context);
		this.context = context;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return goods.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return goods.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = inflater
				.inflate(R.layout.item_dactor_pinglun, null);
		
		ImageView pinglunzhu = (ImageView) convertView.findViewById(R.id.pinglunzhu);
TextView tv_pinglunmingzi = (TextView) convertView
				.findViewById(R.id.tv_pinglunmingzi);
		TextView tv_pinglunshijian = (TextView) convertView
				.findViewById(R.id.tv_pinglunshijian);
		TextView tv_pinglunrongnei = (TextView) convertView
				.findViewById(R.id.tv_pinglunrongnei);
	
		if (goods.size()!=0) {
			Map<String, String> eachMap = goods.get(position);
			String url = eachMap.get("headimg");	
			ImageSet(url,pinglunzhu);
			tv_pinglunmingzi.setText(eachMap.get("nickName") + "");
			long  num =  Long.parseLong(eachMap.get("createtime")) ;
			Date data = new Date(num);		
			String dateStr = CommonUtil.getFormatDate("yyyy-MM-dd", data);
			tv_pinglunshijian.setText(dateStr);
			tv_pinglunrongnei.setText(eachMap.get("content") + "");
		}
		
		return convertView;
	}

}
